import { isFunction } from '@/utils/is';

let timer: any = null;
export function useTimeoutFn(handle: Fn<any>, wait: number, native = false) {
  if (!isFunction(handle)) {
    throw new Error('handle is not Function!');
  }
  if (native) {
    handle();
  } else {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(handle, wait);
  }
}